version 14.2
#delimit ;
log using "F:\Government Formation in Asian-Pacific Democracies.log", replace;
set more off;


* ***************************************************************** *;
* ***************************************************************** *;
* File-Name: model2_re_pp.do *;
* Date: 5/30/2022 *;
* Author: MG *;
* Purpose: Analysis [Random Effects, Country Clusters] *;
* Input File: data_stata_pp.dta *;
* Data Output: None *;
* Previous file: None *;
* Machine: laptop *;
* **************************************************************** *;
* **************************************************************** *;

use "F:\Government Formation in Asian-Pacific Democracies\Portfolio Allocation\data_stata_pp.dta", clear;


gen portfolioshare = . ;

replace portfolioshare = party_port2/gov_port2 ;

gen seatshare = . ;

replace seatshare = party_seats/gov_seats ;

gen parliamentary = . ;
 
replace parliamentary = 1 if presidential ==0 ;

replace parliamentary = 0 if presidential == 1 ;

gen seatshare_parl = . ;

replace seatshare_parl = seatshare * parliamentary ;

gen formateur_parl = . ;

replace formateur_parl = formateur * parliamentary ;

gen seat_legpower = . ;

replace seat_legpower = seatshare * legpower ;

gen legpower_parl = . ;

replace legpower_parl = legpower * parliamentary ;

gen formateur_legpower = . ;

replace formateur_legpower = formateur * legpower ;

gen form_legpower_parl = . ;

replace form_legpower_parl = formateur * legpower * parliamentary ;

gen seat_legpower_parl = . ;

replace seat_legpower_parl = seatshare * legpower * parliamentary ;

************************* ;
*  Summarize variables    ;
************************* ;

sum;


********************************************************************** ;
*  Table A.8, Model 2, re-arranged to put seatshare IVs last           ;
* Y = b0 + b1X + b2W + b3Z + b4XW + b5XZ + b6WZ * b7XZW + controls + e ;
*    formateur is X, parliamentary is W, legpower is Z                 ;
* formateur_parl is XW, formateur_legpower is XZ, legpower_parl is WZ, ; 
* form_legpower_parl is XWZ, then control variables, Random Effects    ; 
********************************************************************** ;

xtset countrycode; 

xtreg portfolioshare formateur parliamentary legpower 
formateur_parl formateur_legpower legpower_parl 
form_legpower_parl 
seatshare seatshare_parl seat_legpower seat_legpower_parl, re cluster(countryname) ;
 
log close;
exit;

